package kr.hkit.powerjava.chapter15;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

public class ChangePanel extends JPanel implements ActionListener {
	private JButton btnChangeColr;
	Color color;

	public ChangePanel() {
		initialize();
	}
	
	private void initialize() {
		setLayout(new BorderLayout(0, 0));
		color = new Color(0, 0, 0);
		btnChangeColr = new JButton("색상 변경");
		btnChangeColr.addActionListener(this);
		add(btnChangeColr, BorderLayout.SOUTH);
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(color);
		g.fillRect(10, 10, 430, 280);
	}

	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnChangeColr) {
			actionPerformedBtnChangeColr(e);
		}
	}
	
	protected void actionPerformedBtnChangeColr(ActionEvent e) {
		ColorDlg dlg =new ColorDlg(this);
	}
	
	public void setChangeColor(Color c){
		color = c;
		repaint();
	}
}
